// 2013-7-29下午07:32:06  net.betou.core.service.PostDataAbstract.java

package net.betou.core.service;

import java.util.Map;

import net.betou.core.service.post.Post;
import net.betou.core.service.post.SmsPost;
import net.betou.core.service.post.Task;
import net.betou.trade.main.manager.agencyorproxy.AgencyMng;

import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 发送数据监听的抽象实现
 * @author 叶装装
 */
public class PostDataAbstract < T > implements PostDataListener< T >{

	public void afterChange( T bean, Map< String, Object > map ) {
	}

	public void afterDelete( T bean ) {
	}

	public void afterSave( T bean ) {
	}

	public Map< String, Object > preChange( T bean ) {
		return null;
	}

	public void preDelete( T bean ) {
	}

	public void preSave( T bean ) {
	}
	
	protected String clearHtml( String content ){
		if( StringUtils.isNotBlank( content )){
			content = Jsoup.clean( content, Whitelist.none( ) ); // 清除所有的HTML
		}
		return content;
	}
	
	protected boolean validateSmsSend( String group, String content ){
		return StringUtils.isNotBlank( group ) && StringUtils.isNotBlank( content );
	}
	
	protected void appendTrade( StringBuffer buffer, String key, Object value, boolean isLast ){
		buffer.append( key );
		buffer.append( ":" );
		buffer.append( value );
		if( !isLast ){
			buffer.append( "," );
		}
	}

	@Autowired
	protected Task task;
	@Autowired
	protected Post post;
	@Autowired
	protected AgencyMng mng;
	
	@Autowired
	protected SmsPost smsPost;
}
